package cn.iocoder.yudao.module.engine.controller.app.story;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.engine.controller.app.story.vo.AppStoryDetailRespVO;
import cn.iocoder.yudao.module.engine.controller.app.story.vo.AppStoryPageReqVO;
import cn.iocoder.yudao.module.engine.controller.app.story.vo.AppStoryListRespVO;
import cn.iocoder.yudao.module.resource.api.IStoryApi;
import cn.iocoder.yudao.module.resource.api.model.StoryDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 场景")
@RestController
@RequestMapping("/lm/story")
@Validated
public class AppStoryController {

    @Resource
    private IStoryApi storyApi;

    @RequestMapping(value = "/page", method = {RequestMethod.GET, RequestMethod.POST})
    @Operation(summary = "获得场景分页")
    @PreAuthenticated
    public CommonResult<PageResult<AppStoryListRespVO>> getStoryPage(@RequestBody @Valid AppStoryPageReqVO pageReqVO) {
        PageResult<StoryDTO> pageResult = storyApi.getStoryPage(pageReqVO.getRoleId(), pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppStoryListRespVO.class));
    }

    @GetMapping("/get")
    @Operation(summary = "获得场景详情")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthenticated
    public CommonResult<AppStoryDetailRespVO> getStory(@RequestParam("id") Integer id) {
        StoryDTO story = storyApi.getStory(id);
        return success(BeanUtils.toBean(story, AppStoryDetailRespVO.class));
    }

}